- 
                Notifications
    
You must be signed in to change notification settings  - Fork 421
 
Add an explicit_type TLV syntax for avoiding certain cases of type inference #3301
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add an explicit_type TLV syntax for avoiding certain cases of type inference #3301
Conversation
          Codecov ReportAll modified and coverable lines are covered by tests ✅ 
 Additional details and impacted files@@            Coverage Diff             @@
##             main    #3301      +/-   ##
==========================================
+ Coverage   89.67%   89.72%   +0.04%     
==========================================
  Files         126      126              
  Lines      103165   103747     +582     
  Branches   103165   103747     +582     
==========================================
+ Hits        92510    93083     +573     
- Misses       7935     7949      +14     
+ Partials     2720     2715       -5     
 Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry.  | 
    
0778913    to
    0d7b30d      
    Compare
  
    | 
           I haven't looked for other cases where we can use this syntax to force the type, but if mentioned I can update them in this PR too.  | 
    
option_unit TLV type to fix dependency on fallback of`! -> () There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New syntax LGTM.
0d7b30d    to
    a640926      
    Compare
  
    | 
           Edited: Forgot to remove some things. Updated. git diff-tree -U1 0d7b30d 37e73cadiff --git a/lightning/src/util/ser_macros.rs b/lightning/src/util/ser_macros.rs
index 3837e3f1..8ebbac10 100644
--- a/lightning/src/util/ser_macros.rs
+++ b/lightning/src/util/ser_macros.rs
@@ -287,3 +287,3 @@ macro_rules! _check_decoded_tlv_order {
 	($last_seen_type: expr, $typ: expr, $type: expr, $field: ident, (required, explicit_type: $fieldty: ty)) => {{
-		// no-op
+		_check_decoded_tlv_order!($last_seen_type, $typ, $type, $field, required);
 	}};
@@ -344,3 +344,3 @@ macro_rules! _check_missing_tlv {
 	($last_seen_type: expr, $type: expr, $field: ident, (required, explicit_type: $fieldty: ty)) => {{
-		// no-op
+		_check_missing_tlv!($last_seen_type, $type, $field, required);
 	}};
@@ -387,6 +387,6 @@ macro_rules! _decode_tlv {
 	($outer_reader: expr, $reader: expr, $field: ident, (option, explicit_type: $fieldty: ty)) => {{
-		$field = Some($crate::util::ser::Readable::read(&mut $reader)?);
+		let field: $fieldty = _decode_tlv!($outer_reader, $reader, $field, option); $field = Some(field);
 	}};
 	($outer_reader: expr, $reader: expr, $field: ident, (required, explicit_type: $fieldty: ty)) => {{
-		$field = Some($crate::util::ser::Readable::read(&mut $reader)?);
+		let field: $fieldty = _decode_tlv!($outer_reader, $reader, $field, required); $field = field;
 	}}; | 
    
a640926    to
    37e73ca      
    Compare
  
    c314602    to
    100c99a      
    Compare
  
    …inference This new syntax is used to fix "dependency on fallback of ! -> ()". This avoids cases where code compiles with a fallback of the never type leading to the unit type. The behaviour in Rust edition 2024 would make this a compile error. See: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint/builtin/static.DEPENDENCY_ON_UNIT_NEVER_TYPE_FALLBACK.html#
100c99a    to
    c0d84e8      
    Compare
  
    There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, this is gonna be really nice to use. Pretty straightforward so just gonna land it.
No description provided.